#!/usr/bin/env python
#_*_ coding:utf-8 _*_

import os
from pyscript.controller import Task
from pyscript.core.config import Config
from pyscript.core import Register

class CollectTask(Task):

    def __init__(self):
        config = Config()
        configPath = Register.get('conf', None)
        className = self.__class__.__name__.lower()

        if configPath:
            configFile = os.path.join(configPath, 'collect.yml')

            if os.path.exists(configFile):
                config.load_config(configFile)

        self.config = config.option(className, {})


    def run(self):
        self.url = self.config.get('url', None)

        while True:
            if self.url:
                print "Start collect, url:%s" % self.url
                self.init()
            else:
                self.url = self.config.get('url', None)
                time.sleep(int(self.config.get('circe_sleep', 3600)))


    def init(self):
        pass

